using System;
using System.Data;
using System.Collections.Generic;
using System.Text;

using AIFSDataAccessLayer;
using AIFSCMSDataAccessLayer.Dao;

namespace AIFSCMSDataAccessLayer.DaoImpl
{
    public class ArticleDao : IArticleDao
    {
        IDataExecutionContext dataExecutionContext;

        public ArticleDao(IDataExecutionContext dataExecutionContext)
        {
            this.dataExecutionContext = dataExecutionContext;
        }

        public DataTable GetArticles(string articleTypeCode, string program, bool? activeFlag)
        {
            IDataExecutionContext dataContext = this.DataExecutionContext;
            DalSqlCommand cmd = dataContext.CreateStoredProcCommand("GetArticles");

            cmd.CreateParameter("ARTICLE_TYPE_CODE", articleTypeCode);
            cmd.CreateParameter("PROGRAM", program);
            cmd.CreateParameter("ACTIVE_FLAG", activeFlag);

            DataTable dt = dataContext.ExectuteDataTable(cmd);

            return dt;
        }

        public DataTable GetCriteriaForArticle(int? articleId)
        {
            IDataExecutionContext dataContext = this.DataExecutionContext;
            DalSqlCommand cmd = dataContext.CreateStoredProcCommand("GetCriteriaForArticle");

            cmd.CreateParameter("ARTICLE_ID", articleId);

            DataTable dt = dataContext.ExectuteDataTable(cmd);

            return dt;
        }

        public DataTable GetFragmentForArticle(int? articleId)
        {
            IDataExecutionContext dataContext = this.DataExecutionContext;
            DalSqlCommand cmd = dataContext.CreateStoredProcCommand("GetFragmentForArticle");

            cmd.CreateParameter("ARTICLE_ID", articleId);

            DataTable dt = dataContext.ExectuteDataTable(cmd);

            return dt;
        }

        #region IDataAccessObject Members

        public AIFSDataAccessLayer.IDataExecutionContext DataExecutionContext
        {
            get { return this.dataExecutionContext; }
        }

        #endregion
    }
}
